function TrView(controller, div) {

	var self = this;
	this.newTr = new Transaction();
	this.editTr = this.newTr;

	this.srcAccCombo = new ComboView({
		width: 110,
		valueProp: 'id',
		nullItem: NullUnique,
		requestEvent: 'accounts-request',
		updateEvent: 'accounts-loaded'
	});
	this.dstAccCombo = new ComboView({
		width: 110,
		valueProp: 'id',
		nullItem: NullUnique,
		requestEvent: 'accounts-request',
		updateEvent: 'accounts-loaded'
	});
	this.srcCurCombo = new ComboView({
		width: 50,
		valueProp: 'id',
		nullItem: NullUnique,
		requestEvent: 'currencies-request',
		updateEvent: 'currencies-loaded'
	});
	this.dstCurCombo = new ComboView({
		width: 50,
		valueProp: 'id',
		nullItem: NullUnique,
		requestEvent: 'currencies-request',
		updateEvent: 'currencies-loaded'
	});

	this.render = function() {
		var grid = new Grid(div, { width: '310px', classes: ['grid', 'bordered'], collapsable: true })
			.setHeader('ТРАНЗАКЦИЯ')
			.addRow(new GridRow().addCell('Дата').addCell('<div id="' + div + 'Date"></div>'))
			.addRow(new GridRow().addCell(
				new Table().newRow().addCell(
					new Table().newRow()
						.addCell('Со счета', { classes: ['outcome', 'field-label-top'] })
						.addCell('Сумма', { classes: ['outcome', 'field-label-top'] })
						.addCell('Валюта', { classes: ['outcome', 'field-label-top'] })
					.newRow()
						.addCell('<div id="' + div + 'SrcAccount">')
						.addCell('<div id="' + div + 'SrcSum"></div>')
						.addCell('<div id="' + div + 'SrcCur"></div>'))
				.addCell('<input id="' + div + 'SwapBtn" type="button" value="⇅" />',
					{ rowspan: 2, classes: ['bottom', 'td-hspacer8'] })
				.newRow().addCell(
					new Table().newRow()
						.addCell('На счет', { classes: ['income', 'field-label-top'] })
						.addCell('Сумма', { classes: ['income', 'field-label-top'] })
						.addCell('Валюта', { classes: ['income', 'field-label-top'] })
					.newRow()
						.addCell('<div id="' + div + 'DstAccount">')
						.addCell('<div id="' + div + 'DstSum"></div>')
						.addCell('<div id="' + div + 'DstCur"></div>'))))
			.addRow(new GridRow().addCell('<textarea id="' + div + 'Desc"></textarea>'))
			.addRow(new GridRow().addCell('<div id="' + div + 'Tags"></div>'))
			.addRow(new GridRow()
				.addCell('<span id="' + div + 'ResetBtn" class="link-button">Сбросить</span>')
				.addCell('<input id="' + div + 'SubmitBtn" type="button" />')
				.addCell('<input id="' + div + 'DetachBtn" type="button" value="⎇ Выделить" />'))
			.render();

		createDatePicker(div + 'Date', new Date());
		this.srcAccCombo.render(div + 'SrcAccount');
		createNumberInput(div + 'SrcSum', 80, 22);
		this.srcCurCombo.render(div + 'SrcCur');
		createSimpleButton(div + 'SwapBtn', 24, 70, function() {
			self.swapAccounts();
		});
		this.dstAccCombo.render(div + 'DstAccount');
		createNumberInput(div + 'DstSum', 80, 22);
		this.dstCurCombo.render(div + 'DstCur');
		createTextArea(div + 'Desc', 285, 22, 'описание');
		createLinkButton(div + 'ResetBtn', function() {
			self.resetTransaction();
		});
		createSimpleButton(div + 'SubmitBtn', 90, 24, function() {
			self.submit();
		});
		createSimpleButton(div + 'DetachBtn', 90, 24, function() {
			self.detach();
		});
		this.refreshForm();
	};

	this.swapAccounts = function() {
		var tr = this.editTr;
		var srcAccount = tr.srcAccId;
		var dstAccount = tr.dstAccId;
		tr.srcAccId = dstAccount;
		tr.dstAccId = srcAccount;
		tr.profit *= -1;

		var srcSum = tr.srcSum;
		var dstSum = tr.dstSum;
		tr.srcSum = dstSum;
		tr.dstSum = srcSum;

		var srcCur = tr.srcCurId;
		var dstCur = tr.dstCurId;
		tr.srcCurId = dstCur;
		tr.dstCurId = srcCur;
		this.refreshForm();
	};

	this.setTransaction = function(tr) {
		this.editTr = tr.clone();
		this.refreshForm();
	};

	this.resetTransaction = function() {
		this.editTr = this.newTr;
		this.refreshForm();
		$(this).trigger('tr-reset');
	};

	this.refreshForm = function() {
		var tr = this.editTr;
		el(div + 'Date').jqxDateTimeInput('value', tr.date);
		var sum = (tr.srcSum != null)? tr.srcSum: 0;
		el(div + 'SrcSum').jqxNumberInput('val', sum);
		this.srcAccCombo.selectById(tr.srcAccId);
		this.srcCurCombo.selectById(tr.srcCurId);

		sum = (tr.dstSum != null)? tr.dstSum: 0;
		el(div + 'DstSum').jqxNumberInput('val', sum);
		this.dstAccCombo.selectById(tr.dstAccId);
		this.dstCurCombo.selectById(tr.dstCurId);
		console.log(tr.tags);
		el(div + 'Desc').val(tr.desc);
		el(div + 'SubmitBtn').val(tr.id? '✓ Сохранить': '+ Добавить');
		el(div + 'DetachBtn').attr('disabled', !tr.id);
	};

	this.submit = function() {

	};

	this.detach = function() {

	};

	this.render();
};